var util = require('../../../utils/util.js');
var wxUtil = require('../../../utils/wxUtil.js');
var ajax = require('../../../utils/ajax.js');
var common = require('../../../utils/common.js');
var PageBase = require('../../../common/PageBase.js');
var app = getApp();

Page(common.extendPage(PageBase, {
  data: {
    dataLoaded: false,
    istake: false

  },

  onLoad: function (options) {

    //debugger;
    var orderno = "";
    var customUid = "";
    if (typeof (options.scene) != "undefined" && options.scene != '') {
      var scene = decodeURIComponent(options.scene);
      var m = scene.split(",");
      orderno = m[0];
      customUid = m[1];
    }
    this.setData({
      orderno,
      uid: customUid
    })

    common.initApp({
      loginSuc: () => {
        this._fetch();
      }
    });
  },

  _fetch() {
    var {
      orderno,
      uid
    } = this.data;

    ajax.G({
      url: 'm=order&a=info',
      data: {
        orderno,
        uid
      },
      success: (res) => {
        //debugger;
        var order =res.data;
        this.setData({
          dataLoaded: true,
          order

        });

      }
    });
  },


  _comfiretake(){

    var {
      orderno,
    } = this.data;

    var staffid = app.getEmployeeid();
    if (typeof (staffid) == "undefined" || staffid == ""){
        util.showWarn("员工未登录，请先登录员工账号重新扫码确认提取");
        setTimeout(function(){
          wx.redirectTo({
            url: '/pages/saler/login/index',
          })
        },2500)
    }

    ajax.G({
      url: 'm=store&c=order&a=stafforder',
      data: {
        orderno,
        staffid
      },
      success: (res) => {
        //debugger;
        if( res.code == 1){
          util.showWarn(res.msg);
          return
        };
        var order = res.data;
        this.setData({
          istake: true
        });

      }
    });
    
  }







}));